<template>
  <!-- 添加websocket界面 -->
  <div class="set-websocket">
    <div class="top">{{ topTitle }}</div>
    <el-scrollbar max-height="100%">
      <div class="form">
        <div class="top-title">
          <div class="title">连接配置</div>
          <el-button type="primary" :loading="loading" @click="testConnection">
            <el-icon style="margin-right: 3px"><Link /></el-icon>测试连接
          </el-button>
        </div>
        <el-form :model="form" label-width="auto" style="max-width: 600px">
          <el-form-item label="名称" prop="label">
            <el-input v-model="form.label" maxlength="100" />
          </el-form-item>
          <el-form-item label="连接地址" prop="url">
            <el-input v-model="form.ip" />
          </el-form-item>
          <el-form-item label="请求头参数" prop="headers">
            <json-editor-vue class="editor" v-model="form.headers" />
          </el-form-item>
        </el-form>
      </div>

      <div class="form">
        <div class="top-title">
          <div class="title">订阅主题</div>
          <el-button type="primary" @click="addFormList">
            <el-icon style="margin-right: 3px"><Plus /></el-icon>新增
          </el-button>
        </div>
        <template v-for="(_, index) in formList" :key="index">
          <el-form :model="formList[index]" label-width="auto" inline>
            <el-form-item label="序号">{{ index + 1 }} </el-form-item>
            <el-form-item label="主题名称" prop="label">
              <el-input v-model="formList[index].label" maxlength="100" />
            </el-form-item>
            <el-form-item label="主题路径" prop="url">
              <el-input v-model="formList[index].path" />
            </el-form-item>
            <el-form-item label="请求头参数" prop="headers">
              <el-button plain>
                <el-icon><Plus /></el-icon>
              </el-button>
            </el-form-item>
          </el-form>
        </template>
      </div>

      <div class="form">
        <div class="btns">
          <el-button type="success">保存并建立连接</el-button>
          <el-button type="primary" @click="saveWebSocket">保存</el-button>
          <el-button>取消</el-button>
        </div>
      </div>
    </el-scrollbar>
  </div>
</template>

<script setup lang="ts">

</script>

<style lang="scss" scoped>
.set-websocket {
  flex: 1;
  height: 100vh;
  .top {
    width: 100%;
    background-color: #fff;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    font-weight: bold;
    border-bottom: 1px solid #e6e8f1;
  }
  :deep(.el-scrollbar) {
    height: calc(100vh - 51px);
  }
  .form {
    background-color: #fff;
    margin: 20px;
    padding: 20px;
    border: 1px solid #e6e8f1;
    .btns {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .top-title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .title {
        font-size: 18px;
        font-weight: bold;
      }
      margin-bottom: 20px;
    }
  }
}
</style>
